<template>
  <commonformdialog
    :isshowDialogs="isshowDialog"
    :dialogTitle="dialogTitle"
    @closetextDialog="closeDialog"
    @confirmbtn='confirmbtn'
    :isshowFooter='true'
    :dialogWidth='"30%"'
    :topHeight='"20vh"'
  >
  <el-form ref="passwordform" :model="psData" :rules="rules" size="medium" label-width="100px">
     <el-form-item label="原密码" prop="oldPassword">
    <el-input v-model="psData.oldPassword" placeholder="请输入原密码" clearable show-password
      :style="{width: '100%'}"></el-input>
  </el-form-item>
  <el-form-item label="新密码" prop="newPassword">
    <el-input v-model="psData.newPassword" placeholder="请输入密码" clearable show-password
      :style="{width: '100%'}"></el-input>
  </el-form-item>
  <el-form-item label="确认密码" prop="rePassword">
    <el-input v-model="psData.rePassword" placeholder="请输入确认密码" clearable show-password
      :style="{width: '100%'}"></el-input>
  </el-form-item>
</el-form>

  </commonformdialog>
</template>

<script>
import commonformdialog from '@/components/commondialog/commondialog'

import {updatepassword} from '@/api/common'
export default {
  data() {
    return {
         psData: {
           oldPassword:'',
        newPassword: '',
        rePassword: '',
      },
      rules: {
        oldPassword:[
{
          required: true,
          message: '请输入原密码',
          trigger: 'blur'
        }
        ],
        newPassword: [{
          required: true,
          message: '请输入密码',
          trigger: 'blur'
        }],
        rePassword: [{
          required: true,
          message: '请输入确认密码',
          trigger: 'blur'
        }],
      },
    }
  },
  components: {
    commonformdialog,
  },
  props: {
    //是否显示弹窗
    isshowDialog: {
      type: Boolean,
      default: false,
      required: true,
    },
    //表单的名字
    dialogTitle: {
      type: String,
      default: '',
      required: true,
    },
  },
  methods: {
    closeDialog() {
      this.$emit('closepass')
      //重置表单
     this.$refs['passwordform'].resetFields()
    },
    confirmbtn(){
       this.$refs['passwordform'].validate( async valid => {
        if (!valid) return
        let data = await updatepassword(this.psData)
        if(data.code == '0000'){
          this.$message({
            type: 'success',
            message: '修改密码成功!'
          });
          //关闭弹窗
          this.$emit('setpasswordok')
          //清空数据
          this.$refs['passwordform'].resetFields()
        }
      })
    }
  },
}
</script>

<style scoped lang='scss'>

</style>